import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';

import 'styles/color_styles.dart';
import 'text_theme/default_text_theme.dart';

/* Light Theme
|--------------------------------------------------------------------------
| Theme Config - config/theme.dart
|-------------------------------------------------------------------------- */


ThemeData lightTheme(ColorStyles color) {
  TDTheme.needMultiTheme();
  var jsonString= '''
  {"default":{"ref":{"brandNormalColor":"brandColor6","warningNormalColor":"warningColor6","errorNormalColor":"errorColor6","successNormalColor":"successColor6","brandHoverColor":"brandColor5","brandFocusColor":"brandColor2","brandActiveColor":"brandColor7","brandDisabledColor":"brandColor2","brandLightColor":"brandColor1","warningHoverColor":"warningColor5","warningFocusColor":"warningColor2","warningActiveColor":"warningColor7","warningDisabledColor":"warningColor2","warningLightColor":"warningColor1","errorHoverColor":"errorColor5","errorFocusColor":"errorColor2","errorActiveColor":"errorColor7","errorDisabledColor":"errorColor2","errorLightColor":"errorColor1","successHoverColor":"successColor5","successFocusColor":"successColor2","successActiveColor":"successColor7","successDisabledColor":"successColor2","successLightColor":"successColor1"},"color":{"brandColor1":"#d5e7ff","brandColor2":"#aacfff","brandColor3":"#7fb7ff","brandColor4":"#559eff","brandColor5":"#2a86ff","brandColor6":"#006eff","brandColor7":"#0058df","brandColor8":"#0042bf","brandColor9":"#002da0","brandColor10":"#001780","warningColor1":"#ffe8d5","warningColor2":"#ffd0aa","warningColor3":"#ffb97f","warningColor4":"#ffa155","warningColor5":"#ff8a2a","warningColor6":"#ff7200","warningColor7":"#df5900","warningColor8":"#bf4000","warningColor9":"#a02800","warningColor10":"#800f00","errorColor1":"#fbe0e0","errorColor2":"#f6c1c1","errorColor3":"#f2a2a2","errorColor4":"#ee8383","errorColor5":"#e96464","errorColor6":"#e54545","errorColor7":"#cc3842","errorColor8":"#b42b3f","errorColor9":"#9c1f3b","errorColor10":"#831238","successColor1":"#d6f4e4","successColor2":"#adeac8","successColor3":"#84dfad","successColor4":"#5cd492","successColor5":"#33ca76","successColor6":"#0abf5b","successColor7":"#09a755","successColor8":"#078f50","successColor9":"#06774a","successColor10":"#055f44","grayColor1":"#f3f4f7","grayColor2":"#e7eaef","grayColor3":"#cfd5de","grayColor4":"#b7c1ce","grayColor5":"#9eacbe","grayColor6":"#8697ad","grayColor7":"#6e829d","grayColor8":"#60708a","grayColor9":"#525e76","grayColor10":"#444c63","grayColor11":"#363a50","grayColor12":"#292c3d","grayColor13":"#1e222d","grayColor14":"#151822"}}}
  ''';
  var _themeData = TDThemeData.fromJson('default', jsonString);

  return ThemeData(
    extensions: [_themeData!],
    useMaterial3: false,
    primaryColor: color.primaryContent,
    primaryColorLight: color.primaryAccent,
    focusColor: color.primaryContent,
    scaffoldBackgroundColor: color.background,

    // 去除水波纹
    splashColor: Colors.transparent,
    highlightColor: Colors.transparent,
    splashFactory: NoSplash.splashFactory,

    // hintColor: color.primaryAccent,
    dividerTheme: DividerThemeData(color: Colors.grey[100]),
    appBarTheme: AppBarTheme(
      titleTextStyle: defaultTextTheme.titleLarge?.copyWith(
        color: color.appBarPrimaryContent,
      ),
      centerTitle: true,
      iconTheme: IconThemeData(color: color.appBarPrimaryContent),
      elevation: 0.0,
      systemOverlayStyle: SystemUiOverlayStyle.dark,
    ),
    buttonTheme: ButtonThemeData(
      buttonColor: color.buttonPrimaryContent,
      colorScheme: ColorScheme.light(primary: color.buttonBackground),
    ),
    textButtonTheme: TextButtonThemeData(
      style: TextButton.styleFrom(foregroundColor: color.primaryContent),
    ),
    elevatedButtonTheme: ElevatedButtonThemeData(
      style: TextButton.styleFrom(
          foregroundColor: color.buttonPrimaryContent,
          backgroundColor: color.buttonBackground),
    ),
    bottomNavigationBarTheme: BottomNavigationBarThemeData(
      backgroundColor: color.bottomTabBarBackground,
      unselectedIconTheme:
          IconThemeData(color: color.bottomTabBarIconUnselected,size: 24),
      selectedIconTheme: IconThemeData(color: color.bottomTabBarIconSelected,size: 24),
      unselectedLabelStyle: TextStyle(color: Colors.white),
      selectedLabelStyle: TextStyle(color: Colors.white),
      selectedItemColor: color.bottomTabBarLabelSelected,
    ),
    // textTheme: lightTheme,
    colorScheme: ColorScheme.light(
        background: color.background, primary: color.primaryAccent),
  );
}

/*
|--------------------------------------------------------------------------
| Light Text Theme
|--------------------------------------------------------------------------
*/

TextTheme _textTheme(ColorStyles colors) {
  Color primaryContent = colors.primaryContent;
  TextTheme textTheme = const TextTheme().apply(displayColor: primaryContent);
  return textTheme.copyWith(
      labelLarge: TextStyle(color: primaryContent.withOpacity(0.8)));
}
